<template>

  <div class="app-container">
    <el-form style="margin-top: 10px">
      <el-form-item label="检查日期">
        <!-- <el-select clearable v-model="form.inspectDate" placeholder="点击选择时间" multiple style="width:100%">
					<el-option v-for="item in 31" :key="item" :value="item">{{item}}</el-option>
				</el-select> -->
        <el-date-picker
          v-model="form.inspectDate"
          type="date"
          style="width:100%"
        />
      </el-form-item>

      <el-form-item label="航班号">
        <el-input clearable v-model="form.flightNumber" placeholder="航班号" style="width:100%">
				</el-input>
      </el-form-item>

      <el-form-item label="机号">
        <el-input clearable v-model="form.machineNumber" placeholder="机号" style="width:100%">
        </el-input>
      </el-form-item>

      <el-form-item label="停机位">
        <el-input clearable v-model="form.stand" placeholder="停机位" style="width:100%">
        </el-input>
      </el-form-item>

      <el-form-item label="工单类型">
        <el-select clearable v-model="form.type" placeholder="点击选择工单类型" style="width:100%">
					<el-option v-for="item in columns1" :key="item.value" :value="item.value" :label="item.text"></el-option>
				</el-select>
      </el-form-item>

      <div style="margin: 16px;">
        <el-button round
                    block
                    type="primary"
                    @click="onSubmit">
          确定
        </el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
import { add, updateHeadById } from '@/api/airport/outfield'
export default {
  name: "SelectMore13",
  props: {
    edit: {
      type: Boolean,
      default: false
    },
    editData: {
      default: 0
    },
    editId: {
      type: [String, Number],
    },
  },
  computed: {
  },
  watch: {
    editData: {
      handler (val) {
        if (val && Object.keys(this.editData).length > 0) {
          this.form.inspectDate = this.editData.inspectDate;
          this.form.flightNumber = this.editData.flightNumber;
          this.form.machineNumber = this.editData.machineNumber;
          this.form.stand = this.editData.stand;
          this.form.typeName = this.editData.typeName;
          this.form.type = this.editData.type;

          for (let i of this.columns1) {
            if (i.value == this.form.type) {
              this.form.typeName = i.text;
            }
          }
        }

      },
      deep: true,
      immediate: true
    }
  },
  data () {
    return {
      result: '',
      result1: '',
      form: {
        inspectDate: '',
        flightNumber: '',
        machineNumber: '',
        stand: '',
        type: 1,
        typeName: '接机工作',
      },
      showPicker: false,
      showPicker1: false,
      columns: [

      ],
      columns1: [
        {
          text: "接机工作",
          value: 1,
        },
        {
          text: "送机工作",
          value: 2,
        },
        {
          text: "维修检查",
          value: 3,
        },
        {
          text: "长短停及航后离机检查项目",
          value: 4,
        },
      ],

      a1: [],
      a3: [],
      a2: [],
      minDate: new Date(2020, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: ['2021', '01', '01'],
      date_choose: '',

    };
  },
  created () {
    this.getToday();
  },

  methods: {

    getToday () {

      var date = new Date();
      var Y = date.getFullYear().toString();
      var M =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1).toString();
      var D = date.getDate() < 10 ? "0" + date.getDate() : date.getDate().toString();
      var hh = date.getHours() < 10 ? "0" + date.getHours() : date.getHours().toString();
      var mm =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes().toString();
      var ss = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds().toString();

      this.currentDate = [Y, M, D, hh, mm, ss];
      this.form.inspectDate = `${Y}-${M}-${D} ${hh}:${mm}:${ss}`;

    },


    // onConfirm ({ selectedValues }) {
    //   this.form.inspectDate = selectedValues.join('-');
    //   this.showPicker = false;
    // },
    onConfirm (value) {
      this.form.inspectDate = value;
      this.showPicker = false;
    },
    onConfirm1 ({ selectedOptions }) {
      this.form.type = selectedOptions[0]?.value;
      this.form.typeName = selectedOptions[0]?.text;
      this.showPicker1 = false;
    },
    onSubmit () {
      const values = {
        ...this.form,
      };
      if (this.editId) {
        values.id = this.editId;
        updateHeadById(values).then((res) => {
          this.$emit("editS");
        })
      } else {
        add(values).then((res) => {
          if (values.type === 1) {
            this.$router.push({
              path: "/user/content",
              query: {
                source: 'add',
                id: res.data,
              },
            });
          }
          if (values.type === 2) {
            this.$router.push({
              path: "/user/transport",
              query: {
                source: 'add',
                id: res.data,
              },
            });
          }
          if (values.type === 3) {
            this.$router.push({
              path: "/user/repair",
              query: {
                source: 'add',
                id: res.data,
              },
            });
          }
          if (values.type === 4) {
            this.$router.push({
              path: "/user/leave",
              query: {
                source: 'add',
                id: res.data,
              },
            });
          }
        })
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  width: 50%;
  height: 100vh;
  .app-page {
    width: 100%;
    height: calc(100% - 50px);
  }
  .app-footer {
    background-color: #f7f8fa;
    z-index: 2000;
  }
}

::v-deep .van-cell--required {
   &:before{
     content: ''
   }
   .van-cell__title.van-field__label {
     span {
       position: relative;
       &:before {
         position: absolute;
         right: -8px;
         color: #ee0a24;
         font-size: 14px;
         content: '*';
       }
     }
   }
 }
</style>
